/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MaterialPack;

import Supporter.ImageSupporter;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author Van persie
 */

public class InfoBar extends MaterialObject {
    private int ratio;    // tinh bang %
    int colR,colG,colB;
    int side;
    public static final int VERTICAL = 1;
    public static final int HORIZON = 0;
    public Image displaybar;
    public Image displaymask;
    public InfoBar(String path,String mask,int _side, int val, int x,int y, int wid,int hei)
    {
        side = _side;
        ratio = val;
        setxPos(x);
        setyPos(y);
        setWidth(wid);
        setHeight(hei);
        ImageSupporter imgSupporter = new ImageSupporter();
        
        if(path != null)
            displaybar = imgSupporter.getImage(path);
        if(mask != null)
            displaymask = imgSupporter.getImage(mask);
        if(_side == VERTICAL)
        {
            displaybar = ImageSupporter.scaleImage(Image.createImage(displaybar, 0, 0, displaybar.getWidth(), displaybar.getHeight(), Sprite.TRANS_MIRROR_ROT90),width,height);
            displaymask =ImageSupporter.scaleImage( Image.createImage(displaymask, 0, 0, displaymask.getWidth(), displaymask.getHeight(),Sprite.TRANS_MIRROR_ROT90),width,height);
        }
        else
        {
            displaybar = ImageSupporter.scaleImage(displaybar,width,height);
            displaymask =ImageSupporter.scaleImage( displaymask,width,height);
        }
        
        super.GetGraphicsInfo(x, y, wid, hei);
        //super.LoadImage(path);
        //background = ImageSupporter.transparent(background);
        colR = 0;
        colR = 0;
        colR = 0;
    }
    public void SetColor(int r,int g, int b)
    {
        colR = r;
        colG = g;
        colB = b;
    }
    public void paint(Graphics g)
    {
        //int color = g.getColor();
        //g.setColor(colR, colG, colB);
        
        if(side == HORIZON)
        {
            if(displaybar != null && displaymask != null)
            {
                g.drawImage(displaybar, getxPos(), getyPos(), Graphics.TOP|Graphics.LEFT);
                g.setClip(xPos+(getWidth())*getRatio()/100, yPos, getWidth()-(getWidth())*getRatio()/100, height);
                g.drawImage(displaymask, getxPos(), getyPos(),Graphics.TOP|Graphics.LEFT);
                g.setClip(0,0,240,320);
            }
            else
                g.fillRect(getxPos(), getyPos(), (getWidth())*getRatio()/100, getHeight());
        }
        else 
        {
             
            if(displaybar != null && displaymask != null)
            {
                g.drawImage(displaybar, getxPos(), getyPos(), Graphics.TOP|Graphics.LEFT);
                g.setClip(xPos, yPos+(getHeight())*getRatio()/100, xPos, getHeight()-(getHeight())*getRatio()/100);
                g.drawImage(displaymask, getxPos(), getyPos(),Graphics.TOP|Graphics.LEFT);
                g.setClip(0,0,240,320);
            }
            else 
                g.fillRect(getxPos(), getyPos(), (getWidth()), (getHeight())*getRatio()/100);
        }
        //g.drawImage(background, xPos, yPos,Graphics.TOP|Graphics.LEFT);
        //g.setColor(color);
        //g.drawRect(getxPos(), getyPos(), getWidth(), getHeight());
    }

    /**
     * @return the ratio
     */
    public int getRatio() {
        return ratio;
    }

    /**
     * @param ratio the ratio to set
     */
    public void setRatio(int ratio) {
        this.ratio = ratio;
    }
}
